package com.lehuowujie.lehuomarket.base;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.lehuowujie.lehuomarket.R;
import com.lehuowujie.lehuomarket.util.UtilIntent;

/**
 * Created by 王瑞铭 on 2017/1/13.
 */
public abstract class BaseFragment extends Fragment {

    public View mContentView;

    public abstract int createView();

    public abstract void initView();

    public abstract void initEvent();

    /**
     * 返回按键
     */
    private LinearLayout back_layout;

    /**
     * 标题
     */
    private TextView toolBarTitle;

    /**
     * 右侧标题
     */
    private TextView toolbarRight;

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        mContentView = inflater.inflate(createView(),container,false);
        return mContentView;
    }

    @Override
    public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);
        initView();
        initEvent();
    }

    /**
     * 初始化toolbar
     * @param
     */
    public void initToolBar(){
        back_layout = (LinearLayout) mContentView.findViewById(R.id.back_layout);
        toolBarTitle = (TextView) mContentView.findViewById(R.id.toolbar_title);
        toolbarRight = (TextView) mContentView.findViewById(R.id.toolbar_right);
        toolbarRight.setVisibility(View.GONE);
        back_layout.setVisibility(View.GONE);
    }

    /**
     * 设置toolbar的返回按键
     */
    public void setBack(boolean isBack)
    {
        if (isBack)
            back_layout.setVisibility(View.VISIBLE);
        else
            back_layout.setVisibility(View.GONE);
    }

    /**
     * 设置toolbar的标题
     * @param resId
     */
    public void setTitle(int resId)
    {
        toolBarTitle.setText(getString(resId));
    }

    /**
     * 设置toolbar的标题
     * @param title
     */
    public void setTitle(String title)
    {
        toolBarTitle.setText(title);
    }

    /**
     * 设置toolbar的右侧标题
     * @param resId
     */
    public void setToolBarRightTitle(int resId)
    {
        toolbarRight.setVisibility(View.VISIBLE);
        toolbarRight.setText(getString(resId));
    }

    /**
     * 设置toolbar的右侧标题
     * @param rightTitle
     */
    public void setToolBarRightTitle(String rightTitle)
    {
        toolbarRight.setVisibility(View.VISIBLE);
        toolbarRight.setText(rightTitle);
    }

}
